package DP;

import java.util.Scanner;

/**
 * @author dx
 * @version 1.0
 * @date 2022/5/16 9:21
 * @description: 力扣121 买卖股票的最佳时机
 */
public class MaxProfit {
    public static void main(String[] args) {
        Scanner sr = new Scanner(System.in);
        String  [] str = sr.nextLine().split(" ");
        int [] price = new int[str.length];
        for(int i =0;i < str.length;i++){
            price[i] = Integer.parseInt(str[i]);
        }
        System.out.println(new MaxProfit_Solution().maxProfit(price));

    }
}

class MaxProfit_Solution{


    public int maxProfit(int [] price){
        int max_profit = Integer.MIN_VALUE;
        for(int i =0;i < price.length;i++){
            int buy = price[i];
            for(int j = i+1;j < price.length; j++){
                max_profit = Math.max(max_profit, price[j] - buy);
            }
        }
        if(max_profit <=0){
            max_profit = 0;
        }
        return max_profit;
    }
    public int maxProfit2(int [] price){
        int minprice = Integer.MAX_VALUE;
        int maxprofit = 0;
        for(int i = 0;i<price.length;i++){
            if(price[i] < minprice){
                minprice = price[i];
            }else if(price[i] - minprice > maxprofit){
                maxprofit = price[i] - minprice;
            }
        }
        return maxprofit;
    }
}